﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Estimate.Common.DataFileFinder
{
    public class UserSiteForeFinder:IDataFileFinder
    {
        public string[] GetFileFromDirectory(DateTime dt, string dirPath)
        {
            DirectoryInfo thisOne = new DirectoryInfo(dirPath);
            IDataFileFinder siteForeFinder = new SiteForeFinder();
            List<string> result = new List<string>();

            foreach (DirectoryInfo sub in thisOne.GetDirectories())
            {
                string userdir = string.Format("{0}/{1}/", sub.FullName, dt.Year.ToString());
                if (Directory.Exists(userdir))
                {
                    result.AddRange(getFileFromDirectory(dt, userdir));
                }
            }
            return result.ToArray();
        }

        public string[] getFileFromDirectory(DateTime dt, string dirPath)
        {
            List<string> result = new List<string>();

            string[] clk = new string[] { "08", "20" };
            string[] spn = new string[] { "024", "048", "072", "096", "120", "144", "168" };

            string filename;

            foreach (string clock in clk)
            {
                foreach (string span in spn)
                {
                    filename = "RS" + dt.ToString("MMdd" + clock + "." + span);

                    if (File.Exists(dirPath + filename))
                    {
                        result.Add(dirPath + filename);
                    }
                }
            }
            return result.ToArray();
        }

        public string[] GetFileNames(DateTime dt)
        {

            string userdir = string.Format("{0}/{1}/", "zdzd", dt.Year.ToString());
            IDataFileFinder siteForeFinder = new SiteForeFinder();
            string[] files = siteForeFinder.GetFileNames(dt);
            string[] result = new string[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                result[i] = userdir + files[i];
            }
            return result;
        }


        public Dictionary<string, string[]> GetFileListFromDirectory(DateTime dt, string dirPath)
        {
            throw new NotImplementedException();
        }
    }
}
